﻿using System;
using System.Data;
using System.Data.Common;
using System.Globalization;
using Gammar.Price.ObjectModel;
using Longbow.Data;

namespace Gammar.Price.DataAccess
{
    /// <summary>
    /// 
    /// </summary>
    public partial class ViewAvailableClass : ReaderCommand<ViewAvailableClassEntity>
    {   
        /// <summary>
        /// 
        /// </summary>            
        protected override CommandType CommandType
        {
            get { return CommandType.Text; }
        }

        private string _criteria;
        
        /// <summary>
        /// 
        /// </summary>
        public string Criteria
        {
            get { return _criteria; }
            set { _criteria = value; }
        }
        
        /// <summary>
        /// 
        /// </summary>
        protected override string CommandText
        {
            get
            {
                string sql = "select * from ViewAvailableClass";
                if (!string.IsNullOrEmpty(Criteria))
                    sql = string.Format(CultureInfo.InvariantCulture, "{0} {1}", sql, Criteria);
                return sql;
            }        
        }

        /// <summary>
        /// 
        /// </summary>            
        protected override void AddParameters(DbParameterCollection parameters, DBAccess db)
        {

        }

        /// <summary>
        /// 
        /// </summary>            
        protected override ViewAvailableClassEntity ParseRow(DbDataReader reader)
        {
            ViewAvailableClassEntity obj = new ViewAvailableClassEntity();
            obj.Pclass_id = (Guid?)DBAccess.ToObjectValue(reader["Pclass_id"]);
            obj.Pclass_name = (string)DBAccess.ToObjectValue(reader["Pclass_name"]);
            obj.Pclass_comment = (string)DBAccess.ToObjectValue(reader["Pclass_comment"]);
            obj.Cclass_id = (Guid?)DBAccess.ToObjectValue(reader["Cclass_id"]);
            obj.Cclass_name = (string)DBAccess.ToObjectValue(reader["Cclass_name"]);
            obj.Cclass_table = (string)DBAccess.ToObjectValue(reader["Cclass_table"]);
            obj.Cclass_comment = (string)DBAccess.ToObjectValue(reader["Cclass_comment"]);
            obj.Cclass_format = (string)DBAccess.ToObjectValue(reader["Cclass_format"]);
            return obj;
        }
    }
}